const handleRequest = (leftView) => {
  const regxArray = [
    /api\/public\/kimiplus/,
    /verificationCode\/getLoginVerifyCode/
  ]

  // 仅能拿到url及header
  leftView.webContents.session.webRequest.onCompleted({
    urls: ['https://kimi.moonshot.cn/*'],
    types: ['xhr']
  }, (details) => {
    console.log('request url:', details.url, details.requestHeaders);
  });

  leftView.webContents.debugger.on('message', (event, method, params) => {
    if (method === 'Network.responseReceived') {
      if (regxArray.some(reg => reg.test(params.response.url))) {
        console.log('debugger url:',params.response.url, params.requestId)
        
        leftView.webContents.debugger.sendCommand('Network.getResponseBody', { requestId: params.requestId }, (error, result) => {
          console.log(result);
        }).catch(err => {
          console.log('catch:',params.response.url, err);
        })
      }
    }
  })
}

export default handleRequest
